import { defineConfig } from 'vite'
import { resolve } from 'path'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'


function pathResolve(dir) {
  return resolve(process.cwd(), '.', dir)
};
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    // 按需引入的配置
    AutoImport({
      resolvers: [ElementPlusResolver()],
      imports: [
        'vue',
        'vue-router',
        'pinia'
      ],
      dts: 'src/auto-import.d.ts', //生成全局文件
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  resolve: {
    alias: {
      '@': pathResolve('src')
    }
  },
  server: {
    host: '192.168.3.12',//ip地址
    port: 8080, //端口号
    open: true, //启动后是否自动打开浏览器
    proxy: {
      // https://cn.vitejs.dev/config/#server-proxy
      "/api": {
        target: "http://192.168.2.20:7011",//连接后端本地地址
        changeOrigin: true,
        // rewrite: (p) => p.replace(/^\/dev-api/, ""),
      },
    },
  },
})
